import { createStore } from 'vuex'

export default createStore({
  state: {
    user: {
      isLoggedIn: false,
      userInfo: null
    }
  },
  mutations: {
    SET_LOGIN_STATE(state, isLoggedIn) {
      state.user.isLoggedIn = isLoggedIn
    },
    SET_USER_INFO(state, userInfo) {
      state.user.userInfo = userInfo
    }
  },
  actions: {
    async login({ commit }, userInfo) {
      // 实现登录逻辑
      commit('SET_USER_INFO', userInfo)
      commit('SET_LOGIN_STATE', true)
    },
    async logout({ commit }) {
      // 实现登出逻辑
      commit('SET_USER_INFO', null)
      commit('SET_LOGIN_STATE', false)
    }
  },
  getters: {
    isLoggedIn: state => state.user.isLoggedIn,
    userInfo: state => state.user.userInfo
  }
}) 